﻿
//更新操作
function UpdateTree(flag, userid) { 
    var urls;

    if (flag === 1)
        urls = "/EasyUI/TreeBox/UpdateUserAction";
    else if (flag === 2)
        urls = "/EasyUI/TreeBox/UpdateUserMenu";

    var list = [];
    var checkedtree = $('#treebox').tree('getChecked');
    var uncheckedtree = $('#treebox').tree('getChecked', 'unchecked');
    var indeterminate = $('#treebox').tree('getChecked', 'indeterminate');

    for (var i = 0; i < checkedtree.length; i++) {
        list.push({
            ActionID: checkedtree[i].id,
            MenuID: checkedtree[i].id,
            HasPermission: 1
        });
    }

    for (var j = 0; j < uncheckedtree.length; j++) {
        list.push({
            ActionID: uncheckedtree[j].id,
            MenuID: uncheckedtree[j].id,
            HasPermission: 0
        });
    }

    for (var k = 0; k < indeterminate.length; k++) {
        list.push({
            ActionID: indeterminate[k].id,
            MenuID: indeterminate[k].id,
            HasPermission: 0
        });
    }

    $.ajax({
        url: urls,
        type: 'post',
        data: { "__RequestVerificationToken": $('[name=__RequestVerificationToken]').val(), list: list, UserID: userid },
        success: function (result) {
            if (result.code === 200) {
                $("#treebox").tree('reload');
                OperateMsg("授权提示", result.msg);
            }
            else if (result.code === 401)
                $.messager.alert('授权提示', result.msg, 'error');
            else
                $.messager.alert('异常提醒', '系统异常', 'error');
        },
        error: function () {
            $.messager.alert('异常错误', '异常错误', 'error');
        }
    });
}
